package com.insight.common.message.listener;

import com.insight.common.message.websocket.WebSocket;
import com.insight.common.mq.aspect.annotation.RedisMessageExtend;
import com.insight.common.mq.stream.Streams;
import com.insight.common.mq.utils.AnalyzeContent;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.stream.StreamListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author JinPengDong
 * @date 2023/10/13
 */
@Component
public class WebSocketSendAllEventListener implements StreamListener<String, MapRecord<String, String, String>> {
    @Override
    @Async("stream-core-pool")
    @RedisMessageExtend(stream = Streams.WEBSOCKET_PUBLICIZE)
    public void onMessage(MapRecord<String, String, String> message) {
        WebSocket.sendAllMessage(AnalyzeContent.getContent(message.getValue()).toJSONString());
    }
}
